package es.tabla.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import es.tabla.utility.xml.ParserXML;


public class MainActivity extends Activity {

    Button botonAñadir;
    Button btabla1;

    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {

        
        super.onCreate(savedInstanceState);
        incializar();
       /* try {
            
            //
            //
            
        } catch (Exception e) {
            mostrarErrores("inicializar: " + e);
        }*/

    }

    
    private void incializar() {
        
        if(ParserXML.exiteTabla())
            cambiarActivity(TipoActivity.PRINCIPAL);
        else
            cambiarActivity(TipoActivity.CREAR_RUTINA);

    /*
        setContentView(R.layout.main);
        botonAñadir = (Button) findViewById(R.id.anadirTabla);
        btabla1 = (Button) findViewById(R.id.tabla1);
        asociarEventos();
        * 
        * 
        */
    }

    private void asociarEventos() {

        botonAñadir.setOnClickListener(new View.OnClickListener() {

            public void onClick(View arg0) {

                cambiarActivity(TipoActivity.ANADIR_TABLA);
            }
        });

        btabla1.setOnClickListener(new View.OnClickListener() {

            public void onClick(View arg0) {

                cambiarActivity(TipoActivity.MOSTRAR_TABLA);
            }
        });



    }

    private void cambiarActivity(TipoActivity tipoActividad) {

        Intent myIntent = null;

        switch (tipoActividad) {

            case PRINCIPAL:
                
                myIntent = new Intent(MainActivity.this, PantallaOpcionesTabla.class);
                break;

            case CREAR_RUTINA:
                myIntent = new Intent(MainActivity.this, CrearTabla.class);
                break;

            default:
                myIntent = null;

        }

        if (myIntent != null) {
            startActivity(myIntent);
        }
    }

    private void mostrarErrores(String inicializar) {
        TextView tv = new TextView(this);
        tv.setText(inicializar);
        setContentView(tv);

    }
}
